

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>选择用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-table-cell{
            height:auto !important;
            white-space: normal;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">

                    <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">

                            <div class="layui-inline">
                                <label class="layui-form-label">手机号</label>
                                <div class="layui-input-block" >
                                    <input class="layui-input" name="mobile" placeholder="请输入手机号" autocomplete="off">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <label class="layui-form-label">用户ID</label>
                                <div class="layui-input-block" >
                                    <input class="layui-input" name="id" placeholder="请输入用户ID" autocomplete="off">
                                </div>
                            </div>

                            <div class="layui-inline">
                                <button class="layui-btn layuiadmin-btn-useradmin" lay-submit
                                        lay-filter="LAY-search">
                                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"> 搜索</i>
                                </button>
                            </div>
                        </div>
                    </div>

                    <table class="layui-hide" id="test-table-reload" lay-filter="test-table-reload"></table>

                </div>
            </div>
        </div>
    </div>
    <div class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
        <input type="hidden" value="" name="userIds" id="userIds"/>
        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="addUserIdsSubmit" id="addUserIdsSubmit" value="确认">
        </div>
    </div>
</div>
<script src="/public/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/public/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form'], function(){
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;

        //监听搜索
        form.on("submit(LAY-search)", function (data) {
            var field = data.field;

            //执行重载
            table.reload('test-table-reload', {
                where: field
            });
        });

        //方法级渲染
        table.render({
            elem: '#test-table-reload'
            ,toolbar: '#test-table-reload-toolbar'
            ,defaultToolbar:['filter']
            ,url: "/user/getSaccUserList"
            ,cellMinWidth: 60
            ,size:'lg'
            ,cols: [[{type:'checkbox'}
                ,{field: 'id', title: '用户ID'}
                , {field: 'mobile', title: '手机号'}
                , {field: 'nickname', title: '昵称'}
                , {field: 'licenses', title: '绑定车牌', templet:function (d) {
                        if (d.licenses.length > 0){
                            return "<div>是</div>";
                        }else{
                            return "<div>否</div>";
                        }
                    }}
                , {field: 'washCount', title: '洗车次数'}
            ]]
            ,page: true
            ,height: 780
        });

        var userIds = $("#userIds").val();
        table.on('checkbox(test-table-reload)', function(data){
            if(data.type=="all"){
                if(data.checked) {
                    var checkStatus=table.checkStatus("test-table-reload");
                    var d = checkStatus.data;
                    for(var i=0;i<d.length;i++) {
                        userIds = userIds + d[i].id + ",";
                    }
                }else{
                    userIds="";
                }
            }else if(data.type=="one") {
                if (data.checked) {
                    userIds = userIds + data.data.id + ",";
                } else {
                    userIds = userIds.toString().replace(data.data.id + ",", "");
                }
            }
            $("#userIds").val(userIds);
        });

    });
</script>
</body>
</html>